function model = ensemble_wrap(coverMat, stegoMat, d_sub, L, ratio, mode, verbose, loops)
%% ensemble_wrap
% scripts to use ensemble easily.
% settings for ensemble:
%   seed_trntst (random value)
%   cover <= 'tmp_cover.mat' (F: coverMat, names: auto generated)
%   stego <= 'tmp_stego.mat' (F: stegoMat, names: auto generated)
%   d_sub <= d_sub
%   L <= L
%   verbose <= verbose
%
% input:
%   coverMat : M*N matrix for training data (class 0).
%   stegoMat : L*N matrix for training data (class 1).
%   mode  : 'same'  - use same names for all data.
%          'unique' - use unique names for all data.
%              (every line in coverMat matches stegoMat)
%          'auto' (default)
%   d_sub : 'automatic'(default) or number
%   L     : 'automatic'(default) or number
%   ratio : value between 0..1
%
% output:
%   model : output from ensemble.

if nargin < 3
    d_sub = 'automatic';
end
if nargin < 4
    L = 'automatic';
end
if nargin < 5
    ratio = 0.5;
end

if nargin < 6
    mode = 'auto';
end
if strcmpi(mode, 'auto')
    if isequal(size(coverMat), size(stegoMat))
        mode = 'unique';
    else
        mode = 'same';
    end
end

if nargin < 7
    verbose = 0;
end

if nargin < 8
    loops = 1;
end
%unique tmpname
while 1
    tn = tempname;
    tmp_cover = [tn, '_c.mat'];
    tmp_stego = [tn, '_s.mat'];
    if ~exist(tmp_cover) && ~exist(tmp_stego)
        break
    end
end
createTmpMat(coverMat, tmp_cover, mode);
createTmpMat(stegoMat, tmp_stego, mode);
a = 0;
for i = 1:loops
settings = struct('cover', tmp_cover, 'stego', tmp_stego, ...
    'seed_trntst', randi(100000), 'd_sub', d_sub, 'L', L, ...
    'verbose', verbose, 'ratio', ratio);
model(i) = ensemble(settings);
a = a + model(i).testing_error;
end
a = a / loops;
fprintf(1, 'Accuracy : %0.2f%%', (1-a)*100);
delete(tmp_cover)
delete(tmp_stego)

end
